package cn.bestsign.kt

/**
 * Created by shouren on 2019/8/7.
 */

fun main(args: Array<String>) {


//    val person = Person(name = "shouren", isMarried = true)
//    person.isMarried = false
//
//    print(person)
//
//    val rectangle = Rectangle(4, 4)
//    print(rectangle.isSuquare)


    print(eval(Sum(Sum(Num(1), Num(2)), Num(4))))

}

data class Person(val name: String, var isMarried: Boolean)

class Rectangle(val height: Int, val width: Int) {
    val isSuquare: Boolean
        get() {
            return height == width
        }
}

interface Expr

class Num(val value: Int) : Expr

class Sum(var left: Expr, val right: Expr) : Expr

fun eval(e: Expr): Int =


        when (e) {
            is Num -> e.value
            is Sum -> eval(e.right) + eval(e.left)
            else ->
                throw RuntimeException()

        }